//
//  NRWCarCarListCell.m
//  New_Runway
//
//  Created by mack on 2018/1/24.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "NRWCarCarListCell.h"
#import "NRWWordSizeTool.h"

@interface NRWCarCarListCell ()
@property (weak, nonatomic) IBOutlet UIImageView *leftImage;
@property (weak, nonatomic) IBOutlet UIImageView *rightImage;
@property (weak, nonatomic) IBOutlet UIImageView *mainImage;
@property (weak, nonatomic) IBOutlet UILabel *mainTitle;
@property (weak, nonatomic) IBOutlet UILabel *contentL;
@property (weak, nonatomic) IBOutlet UILabel *typeL;
@property (weak, nonatomic) IBOutlet UILabel *priceL;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeLW;
@property (weak, nonatomic) IBOutlet UILabel *wan;
@property (weak, nonatomic) IBOutlet UILabel *saleTime;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *wanWidth;

@end

@implementation NRWCarCarListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.backView.backgroundColor = [UIColor colorWithRed:234/255.0 green:234/255.0 blue:234/255.0 alpha:0.6];
}
- (void)setType:(NSString *)type{
    _type = type;
}
-(void)setIsBuyCar:(BOOL)isBuyCar{
    _isBuyCar = isBuyCar;
}
-(void)setCarModel:(Result *)carModel{
    _carModel = carModel;
    
    [self.mainImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@.r_240xh_170",ImageApi,carModel.carImageUrl]] placeholderImage:[UIImage imageNamed:@"tu"]];
    self.mainTitle.text =carModel.carTitle;
    
    self.rightImage.image = [UIImage imageNamed:@""];;

    if (carModel.carOrderState == 1 ) {
        self.rightImage.image = [UIImage imageNamed:@"mark-b"];;
    }
    if (carModel.carBargainPriceState == 1 ) {
        self.rightImage.image = [UIImage imageNamed:@"mark-c"];;
    }
    
    if (carModel.carRetailPrice <= 0) {
        self.priceL.text = @"价格面议";
        self.priceL.font = [UIFont boldSystemFontOfSize:13];
        self.wan.hidden = YES;
        self.wanWidth.constant = 0;
    }else{
        self.priceL.text =  [NSString stringWithFormat:@"%.2f",(CGFloat)carModel.carRetailPrice];
        self.priceL.font = [UIFont boldSystemFontOfSize:22];
        self.wanWidth.constant = 0;
        self.wanWidth.constant = 12;
        self.wan.hidden = NO;

    }
    
    NSString *carSctockStr;
    if (carModel.carStockState == 0) {
        carSctockStr = @"未完成入库";
    }else if (carModel.carStockState == 1){
        carSctockStr = @"审核驳回";
    }else if (carModel.carStockState == 2){
        carSctockStr = @"撤销入库";
    }else if (carModel.carStockState == 10){
        carSctockStr = @"入库审核";
    }else if (carModel.carStockState == 20){
        carSctockStr = @"已入库";
        if (carModel.carSaleState == 0) {
            carSctockStr = @"未上架";
        }else if (carModel.carSaleState == 10){
            carSctockStr = @"上架中";
        }else if (carModel.carSaleState == 20){
            carSctockStr = @"已上架";
            
        }else if (carModel.carSaleState == 30){
            carSctockStr = @"已下架";
        }
        
    }else if (carModel.carStockState == 30){
        carSctockStr = @"出库审核";
    }else if (carModel.carStockState == 40){
        carSctockStr = @"已出库";
    }else{
        carSctockStr = @"--";
    }
    NSString *carAuthStr;
    if (carModel.carAuthState == 0) {
        if (carModel.carDetectState == 500) {
            carAuthStr = @"未初检";
        }else if (carModel.carDetectState == 510){
            carAuthStr = @"初检不通过";
        }else if (carModel.carDetectState == 520){
            carAuthStr = @"初检通过";
        }else if (carModel.carDetectState == 530){
             carAuthStr = @"申请复检中";
        }else if (carModel.carDetectState == 540){
             carAuthStr = @"复检完成";
        }
        self.leftImage.hidden = YES;

    }else{
        carAuthStr = @"已认证";
        self.leftImage.hidden = NO;
    }
  
    if (_isBuyCar == YES) {
        self.typeL.text = [NSString stringWithFormat:@"%@ / %@",carModel.shop.market.city.cityName,carModel.shop.shopName];
        self.typeL.textColor = UIColorHex(0x989898);
        NSString *time = [NRWCarTurnTime timestampSwitchTime:carModel.carSaleTime andFormatter:@"YYYY-MM-dd"];
        self.saleTime.text = [NRWCarTurnTime formateDate:time withFormate:@"YYYY-MM-dd"];
        self.saleTime.textColor = [UIColor lightGrayColor];
        self.timeLW.constant = 70;

    }else{
        self.typeL.text = [NSString stringWithFormat:@"%@ / %@",carSctockStr,carAuthStr];
        self.typeL.textColor = MAIN_NAV_COLOR();
        ///143青岛苏尚万车
        if (carModel.carSaleState == 20 && [carModel.marketId isEqualToString:@"143"] && carModel.loanBrandId != 0) {
            if (carModel.valuationDealerLowBuyPrice != 0) {
                NSString *money = [NSString stringWithFormat:@"可贷金额≈%.2f万元",carModel.valuationDealerLowBuyPrice * 0.7];
                self.saleTime.text = money;
                self.saleTime.textColor = [UIColor redColor];
                self.timeLW.constant = [NRWWordSizeTool countTextWidth:money font:11.0];
                
            }else{
                self.saleTime.text = @"";
                
            }
        }else{
            self.saleTime.text = @"";
        }
       
  
    }
    NSString *mileageStr;
    if ([carModel.carMileage doubleValue] <= 0) {
        mileageStr = @"未输入里程";
    }else{
     
        if ([carModel.carMileage doubleValue] < 0.1) {
            mileageStr = [NSString stringWithFormat:@"%.f公里", [carModel.carMileage doubleValue] *10000];
            
        }else{
            mileageStr = [NSString stringWithFormat:@"%.2f万公里",[carModel.carMileage doubleValue]];
            
        }
        
    }
    if (carModel.carLicenceState == 1 ) {
        self.contentL.text = [NSString stringWithFormat:@"%@ | %@年",mileageStr, [NRWCarTurnTime timestampSwitchTime:carModel.carLicenceDate andFormatter:@"YYYY"]];
    }else if (carModel.carLicenceState == 2){
        self.contentL.text = [NSString stringWithFormat:@"%@ | 未上牌",mileageStr];
    }else if (carModel.carLicenceState == 3 ){
        self.contentL.text = [NSString stringWithFormat:@"%@ | 新车",mileageStr];
    }


}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
